﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HellCook.Model;

namespace HellCook.WinApp_WPF.RecipeManager.RecipeFunctionality
{
    /// <summary>
    /// Interaction logic for SearchRecipe.xaml
    /// </summary>
    public partial class SearchRecipe : Window
    {
        public SearchRecipe()
        {
            InitializeComponent();

            DameTodasLasRecetas();
        }

        private void DameTodasLasRecetas()
        {
            this.dataGrid_ResultSearch.ItemsSource = HellCook.Business.Receta_Buscador.ObtenerTodasLasRecetas();
        }

        private void textBox_Namerecipe_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (String.IsNullOrEmpty(textBox_NameRecipe.Text))
            {
                DameTodasLasRecetas();
            }
            else
            {
                this.dataGrid_ResultSearch.ItemsSource = null;
                this.dataGrid_ResultSearch.ItemsSource = HellCook.Business.Receta_Buscador.ObtenerTodosLasRecetasSimilarA(this.textBox_NameRecipe.Text);
            }
        }

        private void dataGrid_ResultSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.dataGrid_ResultSearch.SelectedIndex >= 0)
            {
                Receta RecetaSeleccionada = (Receta)this.dataGrid_ResultSearch.SelectedItem;
                this.dataGrid_ListaIngredientes.ItemsSource = RecetaSeleccionada.Lista_Ingredientes;
            }
            else
            {
                this.dataGrid_ListaIngredientes.ItemsSource = null;
            }
        }

        private void ModificarReceta(object sender, MouseButtonEventArgs e)
        {
            if (this.dataGrid_ResultSearch.SelectedIndex >= 0)
            {
                Receta RecetaSeleccionada = (Receta)this.dataGrid_ResultSearch.SelectedItem;
                MessageBoxResult result;
                result = MessageBox.Show("¿Desea Modificar la Receta?", "Mensaje", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    Receta_Administrador.FuncionalidadReceta.ModificarReceta ModificarReceta = new Receta_Administrador.FuncionalidadReceta.ModificarReceta(RecetaSeleccionada);
                    ModificarReceta.ShowDialog();                    
                }
            }
        }
    }
}
